from .base import db
from datetime import datetime

class Education(db.Model):
    __tablename__ = 'education'
    id = db.Column(db.Integer, primary_key=True, autoincrement=True)
    employee_id = db.Column(db.Integer, db.ForeignKey('employee.id'), nullable=False)
    degree = db.Column(db.String(50), nullable=False)  # 学历
    major = db.Column(db.String(100), nullable=False)  # 专业
    school = db.Column(db.String(100), nullable=False)  # 毕业院校
    graduation_date = db.Column(db.Date, nullable=False)  # 毕业时间
    degree_type = db.Column(db.String(50), nullable=False)  # 学历性质
    is_double_certificate = db.Column(db.Boolean, default=False)  # 是否双证
    created_at = db.Column(db.DateTime, default=datetime.utcnow)
    updated_at = db.Column(db.DateTime, default=datetime.utcnow, onupdate=datetime.utcnow)

    def to_dict(self):
        return {
            'id': self.id,
            'employee_id': self.employee_id,
            'degree': self.degree,
            'major': self.major,
            'school': self.school,
            'graduation_date': self.graduation_date.isoformat() if self.graduation_date else None,
            'degree_type': self.degree_type,
            'is_double_certificate': self.is_double_certificate,
            'created_at': self.created_at.isoformat() if self.created_at else None,
            'updated_at': self.updated_at.isoformat() if self.updated_at else None
        } 